package main

import (
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/broker"
	"github.com/micro/go-micro/config"
	"github.com/micro/go-micro/service/grpc"
	_ "github.com/micro/go-plugins/broker/grpc"
	"github.com/micro/go-plugins/broker/rabbitmq"
	_ "github.com/micro/go-plugins/broker/rabbitmq"
	"log"
	"shopping/notification/subscriber"
)

func main() {
	//加载配置项
	err := config.LoadFile("./config.json")
	if err != nil {
		log.Fatalf("Could not load config file: %s", err.Error())
		return
	}

	b := rabbitmq.NewBroker(
		broker.Addrs(config.Get("rabbitmq_addr").String("")),
	)

	b.Init()
	b.Connect()

	//
	service := grpc.NewService(
		micro.Name("go.micro.srv.notification"),
		micro.Version("latest"),
		micro.Broker(b),
	)

	service.Init()

	micro.RegisterSubscriber("notification.submit", service.Server(), new(subscriber.Notification))

	if err := service.Run(); err != nil {
		log.Fatal("run err: ",err)
	}
}
